From d3b172af3bcb32b28b836dc5abf4ec3337428c6c Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Mon, 2 Jun 2014 01:30:21 -0400 Subject: [PATCH] Remove Fallback::iconv() The iconv fallback is, for the most part, a remnant of PHP 4 support. Though iconv was not enabled by default in PHP 4, it is in PHP 5. This is the case even for Windows builds, which use GNU libiconv. As for the major Linux distributions: * Debian, CentOS, Ubuntu -> always enabled * Fedora, Slackware -> .so in the same package, enabled by default * Arch -> .so in the same package, disabled by default * openSUSE -> separate package Change-Id: Ie1112a5742646a0e1f951e188480c23851859320 --- RELEASE-NOTES-1.24 | 3 +++ includes/Fallback.php | 22 ---------------------- includes/GlobalFunctions.php | 10 ---------- includes/installer/Installer.php | 14 ++++++++++++++ includes/installer/i18n/en.json | 1 + includes/installer/i18n/qqq.json | 1 + includes/media/Exif.php | 2 -- includes/utils/ZipDirectoryReader.php | 4 +--- 8 files changed, 20 insertions(+), 37 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index d76cd29a76..c66758fdc6 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -12,6 +12,9 @@ production. * MediaWiki will no longer run if register_globals is enabled. It has been deprecated for 5 years now, and was removed in PHP 5.4. For more information about why, see . +* MediaWiki now requires PHP's iconv extension. openSUSE users may need to + install the php5-iconv package. Users of other systems may need to add + extension=iconv.so to php.ini or recompile PHP without --without-iconv. * The server's canonical hostname is available as $wgServerName, which is exposed in both mw.config and ApiQuerySiteInfo. * Introduced $wgPagePropsHaveSortkey as a backwards-compatibility switch, diff --git a/includes/Fallback.php b/includes/Fallback.php index e38bdf1a70..c4b22f53de 100644 --- a/includes/Fallback.php +++ b/includes/Fallback.php @@ -25,28 +25,6 @@ */ class Fallback { - /** - * @param string $from - * @param string $to - * @param string $string - * @return string - */ - public static function iconv( $from, $to, $string ) { - if ( substr( $to, -8 ) == '//IGNORE' ) { - $to = substr( $to, 0, strlen( $to ) - 8 ); - } - if ( strcasecmp( $from, $to ) == 0 ) { - return $string; - } - if ( strcasecmp( $from, 'utf-8' ) == 0 ) { - return utf8_decode( $string ); - } - if ( strcasecmp( $to, 'utf-8' ) == 0 ) { - return utf8_encode( $string ); - } - return $string; - } - /** * Fallback implementation for mb_substr, hardcoded to UTF-8. * Attempts to be at least _moderately_ efficient; best optimized diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index feca005788..b41ec9ff74 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -35,16 +35,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { * PHP extensions may be included here. */ -if ( !function_exists( 'iconv' ) ) { - /** - * @codeCoverageIgnore - * @return string - */ - function iconv( $from, $to, $string ) { - return Fallback::iconv( $from, $to, $string ); - } -} - if ( !function_exists( 'mb_substr' ) ) { /** * @codeCoverageIgnore diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 7c67ee8dac..cdc8266ce7 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -137,6 +137,7 @@ abstract class Installer { 'envCheckLibicu', 'envCheckSuhosinMaxValueLength', 'envCheckCtype', + 'envCheckIconv', 'envCheckJSON', ); @@ -1206,6 +1207,19 @@ abstract class Installer { return true; } + /** + * @return bool + */ + protected function envCheckIconv() { + if ( !function_exists( 'iconv' ) ) { + $this->showError( 'config-iconv' ); + + return false; + } + + return true; + } + /** * @return bool */ diff --git a/includes/installer/i18n/en.json b/includes/installer/i18n/en.json index b6606a6bc8..f25c562f10 100644 --- a/includes/installer/i18n/en.json +++ b/includes/installer/i18n/en.json @@ -62,6 +62,7 @@ "config-memory-raised": "PHP's memory_limit is $1, raised to $2.", "config-memory-bad": "Warning: PHP's memory_limit is $1.\nThis is probably too low.\nThe installation may fail!", "config-ctype": "Fatal: PHP must be compiled with support for the [http://www.php.net/manual/en/ctype.installation.php Ctype extension].", + "config-iconv": "Fatal: PHP must be compiled with support for the [http://www.php.net/manual/en/iconv.installation.php iconv extension].", "config-json": "Fatal: PHP was compiled without JSON support.\nYou must install either the PHP JSON extension or the [http://pecl.php.net/package/jsonc PECL jsonc] extension before installing MediaWiki.\n* The PHP extension is included in Red Hat Enterprise Linux (CentOS) 5 and 6, though must be enabled in /etc/php.ini or /etc/php.d/json.ini.\n* Some Linux distributions released after May 2013 omit the PHP extension, instead packaging the PECL extension as php5-json or php-pecl-jsonc.", "config-xcache": "[http://xcache.lighttpd.net/ XCache] is installed", "config-apc": "[http://www.php.net/apc APC] is installed", diff --git a/includes/installer/i18n/qqq.json b/includes/installer/i18n/qqq.json index d0a37a7219..6ec724fdd9 100644 --- a/includes/installer/i18n/qqq.json +++ b/includes/installer/i18n/qqq.json @@ -80,6 +80,7 @@ "config-memory-raised": "Parameters:\n* $1 is the configured memory_limit.\n* $2 is the value to which memory_limit was raised.", "config-memory-bad": "Parameters:\n* $1 is the configured memory_limit.", "config-ctype": "Message if support for [http://www.php.net/manual/en/ctype.installation.php Ctype] is missing from PHP.\n{{Related|Config-fatal}}", + "config-iconv": "Message if support for [http://www.php.net/manual/en/iconv.installation.php iconv] is missing from PHP.\n{{Related|Config-fatal}}", "config-json": "Message if support for [[wikipedia:JSON|JSON]] is missing from PHP.\n* \"[[wikipedia:Red Hat Enterprise Linux|Red Hat Enterprise Linux]]\" (RHEL) and \"[[wikipedia:CentOS|CentOS]]\" refer to two almost-identical Linux distributions. \"5 and 6\" refers to version 5 or 6 of either distribution. Because RHEL 7 likely will not include the PHP extension, do not translate as \"5 or newer\".\n* \"The [http://www.php.net/json PHP extension]\" is the JSON extension included with PHP 5.2 and newer.\n* \"The [http://pecl.php.net/package/jsonc PECL extension]\" is based on the PHP extension, though excludes code some distributions have found unacceptable (see [[bugzilla:47431]]).\n{{Related|Config-fatal}}", "config-xcache": "Message indicates if this program is available", "config-apc": "Message indicates if this program is available", diff --git a/includes/media/Exif.php b/includes/media/Exif.php index b39e042eda..d6301369ce 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -470,8 +470,6 @@ class Exif { $charset = ""; break; } - // This could possibly check to see if iconv is really installed - // or if we're using the compatibility wrapper in globalFunctions.php if ( $charset ) { wfSuppressWarnings(); $val = iconv( $charset, 'UTF-8//IGNORE', $val ); diff --git a/includes/utils/ZipDirectoryReader.php b/includes/utils/ZipDirectoryReader.php index 6be186fc21..454a97bad0 100644 --- a/includes/utils/ZipDirectoryReader.php +++ b/includes/utils/ZipDirectoryReader.php @@ -430,9 +430,7 @@ class ZipDirectoryReader { $year, $month, $day, $hour, $minute, $second ); // Convert the character set in the file name - if ( !function_exists( 'iconv' ) - || $this->testBit( $data['general bits'], self::GENERAL_UTF8 ) - ) { + if ( $this->testBit( $data['general bits'], self::GENERAL_UTF8 ) ) { $name = $data['name']; } else { $name = iconv( 'CP437', 'UTF-8', $data['name'] ); -- 2.20.1